<template>
    <div>
      <div class="option-button">
        <el-button size="small" type="primary" @click="addContent">
          <i class="el-icon-circle-plus-outline"></i>
        </el-button>
        <el-button size="small" type="primary" @click="delAllAuth"> 
          <i class="el-icon-delete"></i>
        </el-button>
      </div>
      <el-table
        :data="menuData"
        stripe
        @selection-change="handleSelectionChange"
        style="width: 100%">
        <el-table-column
          type="index"
          width="50">
        </el-table-column>
        <el-table-column 
        type="selection" 
        width="55">
        </el-table-column>
        <el-table-column
          prop="name"
          label="顺序"
          width="55">
        </el-table-column>
        <el-table-column
          prop="review"
          label="审核状态"
          width="80">
        </el-table-column>
        <el-table-column
          prop="parentNode"
          label="父节点"
          width="80">
        </el-table-column>
        <el-table-column
          prop="name"
          label="栏目名称"
          width="120">
        </el-table-column>
        <el-table-column
          prop="seoUrl"
          label="seoUrl"
          width="120">
        </el-table-column>
        <el-table-column
          prop="description"
          label="描述"
          width="150">
        </el-table-column>
        <el-table-column
          prop="link"
          label="链接"
          min-width="130">
        </el-table-column>
        <el-table-column
          prop="effective"
          label="是否有效"
          width="50">
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          min-width="100">
          <template slot-scope="scope">
            <!-- @click="handleClick(scope.$index, scope.row)"  -->
            <el-button  @click="handleClick(scope.$index, scope.row)"  type="text" size="small">编辑</el-button>

            <el-button @click="handleDelete(scope.$index, scope.row)" type="text" size="small">删除</el-button>
          </template>
          </el-table-column>
      </el-table>
      <el-dialog title="填写栏目信息" :visible.sync="dialogFormVisible">
        <el-form :model="navForm" size="mini" :rules="rules" ref="ruleForm">
          <el-form-item label="审核状态" :label-width="formLabelWidth" prop="review">
            <el-select v-model="navForm.review" placeholder="请选择用户类型">
              <el-option label="操作员" value="shanghai"></el-option>
              <el-option label="审核员" value="beijing"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="栏目户名" :label-width="formLabelWidth" prop="username">
            <el-input v-model="navForm.username" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="描述" :label-width="formLabelWidth" prop="description">
            <el-input v-model="navForm.description" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="seoUrl" :label-width="formLabelWidth" prop="seoUrl">
            <el-input v-model="navForm.seoUrl" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="链接" :label-width="formLabelWidth" prop="link">
            <el-input v-model="navForm.checkpass" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="顺序" :label-width="formLabelWidth" prop='tel'>
            <el-input v-model="navForm.phonenumber" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="父节点" :label-width="formLabelWidth" prop="parentNode">
            <el-input v-model="navForm.parentNode" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="是否有效" :label-width="formLabelWidth">
            <el-switch v-model="navForm.delivery" autocomplete="off"></el-switch>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="updataAuth">确 定</el-button>
        </div>
      </el-dialog>
    </div>
</template>

<script>
import { queryUsers,deleteUser,deleteManyUser,addUser,updateUsers } from "@/api";
export default {
  name: 'authManage',
  data(){
    return{
      menuData:[{
          review: '审核完成',
          name: '王小虎',
          effective: '是',
          parentNode: '无',
          seoUrl: 'announcement',
          description: '上海市普陀区金沙江路 1518 弄',
          link: 'https://element.eleme.cn/#/zh-CN/component/table'
        }],
      multipleSelection:[],
      delarr:"",
      dialogFormVisible:false,
      navForm:{},
      formLabelWidth: '120px',
      rules: {
          username: [
            { required: true, message: '请输入名称', trigger: 'blur' },
            { min: 2, max: 12, message: '长度在 2 到 12 个字符', trigger: 'blur' }
          ],
          description: [
            { required: true, message: '请输入描述内容', trigger: 'blur' },
            { min: 2, max: 60, message: '长度在 2 到 60 个字符', trigger: 'blur' }
          ],
          seoUrl: [
            { required: true, message: '请输入seo', trigger: 'blur' }
          ],
          link: [
            { required: true, message: '请输入链接', trigger: 'blur' }
          ],
          review: [
            { required: true, message: '请选择类型', trigger: 'change' }
          ],
          parentNode: [
            { required: true, message: '请确认是否有父节点', trigger: 'blur' }
          ],
          tel: [
            { required: true, message: '请确认顺序', trigger: 'blur' },
            { type:'number', message: '请输入正确的顺序码', trigger: 'blur' }
          ]
        }
    }
  },
  created(){
    // this.queryUser()
  },
  methods:{
      handleSelectionChange(val){
        // console.log(val)
        var thispage = this;
        thispage.multipleSelection = val;
      },
      // 单个删除
      handleDelete(index,row){
        let data={id:row.id}
        // console.log(data)
        deleteUser(data)
        this.queryUser()
      },
      // 获取编辑用户的信息
      handleClick(index,row){
        this.dialogFormVisible=true
        this.form=row
        console.log(this.form)
      },
      // 更新用户信息api
      updataAuth(){
        this.dialogFormVisible=false
        // updateUsers(this.form)
      },
      // 新增用户
      addContent(){
        this.dialogFormVisible=true
      },
      // 批量删除
      delAllAuth(){
        this.multipleSelection.map(item=>{
          //  this.delarr.push({id:item.id})
          if(!this.delarr){
              this.delarr =  item.id       
          }else{
              this.delarr +=  "," + item.id
          } 
      })
        deleteManyUser({id:this.delarr})
        this.queryUser()
      },
      // 获取全体用户信息api
      async queryUser() {
          let data = await queryUsers();
          this.authManage=data.data.errorMsg
      }
  }
}
</script>

<style scoped>
.option-button{
padding-left:20px;
}
</style>

